<?php
/**
 * @Name: DepartmentController.php
 * @Author: yashuai
 */

namespace App\Http\Controllers\Org;


use App\Http\Logic\Org\DepartmentLogic;
use App\Http\Requests\Org\DepartmentIDRequest;
use App\Http\Requests\Org\DepartmentSaveRequest;
use App\Http\Search\Org\DepartmentSearch;

class DepartmentController
{

    /**
     * @Desc 部门列表
     * @return \Illuminate\Http\JsonResponse
     * @author yashuai
     */
    public function index()
    {
        $result = DepartmentSearch::instance()->index();
        return _success($result);
    }


    /**
     * @Desc 添加部门
     * @param DepartmentSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     * @author yashuai
     */
    public function create(DepartmentSaveRequest $request)
    {
        $result = DepartmentLogic::instance($request->getValidationData())->create();
        return _success($result);
    }

    /**
     * @Desc 编辑部门
     * @param DepartmentSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     * @author yashuai
     */
    public function update(DepartmentSaveRequest $request)
    {
        $validator = [
            'DepartmentID' => 'required|integer'
        ];
        $result = DepartmentLogic::instance($request->getValidationData($validator))->update();
        return _success($result);
    }

    /**
     * @Desc 删除部门
     * @param DepartmentIDRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     * @author yashuai
     */
    public function delete(DepartmentIDRequest $request)
    {
        DepartmentLogic::instance($request->getValidationData())->delete();
        return _success();
    }

}
